﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using DataShower.Interfaces;
using DataShower.Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataShower.ViewModels;

partial class MainWindowViewModel : ObservableObject
{
    [ObservableProperty]
    bool showLoadingWindow;

    [ObservableProperty]
    DataViewModel dataView;

    [ObservableProperty]
    string dataFolder;

    private Dictionary<string, DataViewModel> _datas = new Dictionary<string, DataViewModel>();

    private User userInfo = null;
    public MainWindowViewModel()
    {
        userInfo = User.Current;
        DataFolder = Environment.CurrentDirectory;
    }

    [RelayCommand]
    void Close(IWindowManager window)
    {
        window.CloseDialog(true);
    }

    [RelayCommand]
    void LoadFile(string fileName)
    {
        string filePath = Path.Combine("Data", fileName);
        if (!File.Exists(filePath))
        {
            return;
        }

        if (!_datas.ContainsKey(fileName))
        {
            _datas.Add(fileName, new DataViewModel(filePath));
        }

        DataView = _datas[fileName];
        DataView.InitYAxes();

        ShowLoadingWindow = true;
    }

    [RelayCommand]
    void Return()
    {
        ShowLoadingWindow = false;
    }
}